package com.qingding.activity;

import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.SaveCallback;
import com.qingding.fragment.FragmentFactory;
import com.qingding.fragment.JingXuanFragment;
import com.qingding.R;
import com.qingding.fragment.ShuRiFragment;
import com.qingding.fragment.WoDeFragment;

import com.qingding.view.RadioButtonTools;



/**
 * 这是我们的主活动，继承了ShuRiFragment.OnFragmentInteractionListener接口,WoDeFragment.OnFragmentInteractionListener和JingXuanFragment.OnFragmentInteractionListener
 * 具体实现了这三个接口有什么作用，我们还是暂时先继续往下面看看吧
 */

public class MainActivity extends AppCompatActivity implements ShuRiFragment.OnFragmentInteractionListener,
        WoDeFragment.OnFragmentInteractionListener,
        JingXuanFragment.OnFragmentInteractionListener, View.OnClickListener{
    private FragmentManager mFragmentManager;//FragmentManager
    private RadioGroup radioGroup1;//单选按钮组
    private RadioGroup radioGroup2;
    private LinearLayout linearLayout;//精选分类
    //测试
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取FragmentManager
        mFragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        Fragment fragment = FragmentFactory.getInstanceByIndex(R.id.shuri);
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
        //获取radioGroup控件
        radioGroup1 = (RadioGroup) findViewById(R.id.radio_group);
        //监听点击按钮事件,实现不同Fragment之间的切换
        radioGroup1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentTransaction transaction = mFragmentManager.beginTransaction();
                Fragment fragment = FragmentFactory.getInstanceByIndex(checkedId);


                transaction.replace(R.id.fragment_container, fragment);
                transaction.commit();
            }
        });

        /*radioGroup2 = (RadioGroup) findViewById(R.id.jingxuan_classify_title);
        radioGroup2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                FragmentTransaction transaction = mFragmentManager.beginTransaction();
                Fragment fragment = FragmentFactory.getInstanceByIndex(checkedId);
                transaction.replace(R.id.fragment_container, fragment);
                transaction.commit();
            }
        });*/


        //改变radioButton的大小
        int[] radioButtons = {R.id.jingxuan, R.id.shuri, R.id.wode};
        int[] drawables = {R.drawable.tab_first_background, R.drawable.tab_second_background,
                R.drawable.tab_third_background
        };
        RadioButtonTools.changeSize(radioButtons, drawables, this, 0);





    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }

    @Override
    public void onClick(View view) {
        Toast.makeText(this,"hello",Toast.LENGTH_SHORT).show();
    }

/*    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sendboy:
                Toast.makeText(MainActivity.this, "送男孩", Toast.LENGTH_SHORT).show();
                break;
            default:
                Toast.makeText(MainActivity.this, "其他", Toast.LENGTH_SHORT).show();
                break;

        }
    }*/
}